﻿using System.Linq;
using Ro.Common.RoArgs;

namespace Ro.AssistFunction.PropertyAction
{
    /// <summary>
    /// 对参数的操作行为
    /// </summary>
    public class PropertyAction
    {
        /// <summary>
        /// 新增/更新参数值
        /// </summary>
        /// <param name="oneProperty">待新增/更新的参数</param>
        public void UpdatePropertyValue(Property oneProperty)
        {
            Property tempPro = (from temp in RoPubArgments.SystemProperties where temp.Id == oneProperty.Id select temp).SingleOrDefault();
            //参数查询若不存在
            if (tempPro == null)
            {
                RoPubArgments.SystemProperties.Add(oneProperty);
            }
            //如果存在，则更新参数Value值
            else
            {
                tempPro.Value = oneProperty.Value;
            }
        }


        /// <summary>
        /// 查询参数
        /// </summary>
        /// <param name="id">参数Id</param>
        public string SelectPropertyValue(string id)
        {
            //Linq 查询
            Property pros = (from temp in RoPubArgments.SystemProperties where temp.Id == id select temp).Single();
            string backvalue = pros.Value;
            return backvalue;
        }


        /// <summary>
        /// 删除参数
        /// <para>本方法请谨慎使用</para>
        /// </summary>
        /// <param name="id">参数id</param>
        /// <param name="property">参数类</param>
        public void DeleteProperty(string id, Property property)
        {
            if (id == null)
            {
                RoPubArgments.SystemProperties.Remove(property);
            }
            else
            {
                //Linq 查询
                Property pros = (from temp in RoPubArgments.SystemProperties where temp.Id == id select temp).Single();
                RoPubArgments.SystemProperties.Remove(pros);
            }
        }
    }
}
